package com.yunji.ylexpiration.service.impl;

import com.yunji.ylexpiration.entity.FurnShoppinTrolley;
import com.yunji.ylexpiration.entity.FurnShoppinTrolleyExample;
import com.yunji.ylexpiration.mapper.FurnShoppinTrolleyMapper;
import com.yunji.ylexpiration.service.FurnShoppinTrolleyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/*
购物车Service
 */
@Service
public class FurnShoppinTrolleyServiceimpl implements FurnShoppinTrolleyService {
    @Autowired
    FurnShoppinTrolleyMapper furnShoppinTrolleyMapper;
    @Override
    public int shoppinadd(FurnShoppinTrolley furnShoppinTrolley) {
        if (null==furnShoppinTrolley){
            return 0;
        }
        int i = furnShoppinTrolleyMapper.insertSelective (furnShoppinTrolley);
        return i;
    }

    @Override
    public int quantityadd(Integer shopid,FurnShoppinTrolley furnShoppinTrolley) {
        if (shopid==null||null==furnShoppinTrolley){
            return 0;
        }
        furnShoppinTrolley.setId (shopid);
        return furnShoppinTrolleyMapper.updateByPrimaryKey (furnShoppinTrolley);
    }

    @Override
    public int quantitysubtract(Integer shopid,FurnShoppinTrolley furnShoppinTrolley ) {
        if (shopid==null||null==furnShoppinTrolley){
            return 0;
        }
        furnShoppinTrolley.setId (shopid);
        return furnShoppinTrolleyMapper.updateByPrimaryKey (furnShoppinTrolley);
    }

    @Override
    public FurnShoppinTrolley selfurnshoopingtrolleyByid(Integer shoppid) {
        return furnShoppinTrolleyMapper.selectByPrimaryKey (shoppid);
    }

    @Override
    public int delfurnshoopingtrolleyByid(Integer id) {
        if (id==null||id==0){
            return 0;
        }
        return furnShoppinTrolleyMapper.deleteByPrimaryKey (id);
    }

    @Override
    public List<FurnShoppinTrolley> selfurnshoopingtrolleyByuserid(Integer userid) {
        if (userid<1) {
            return null;
        }
        return furnShoppinTrolleyMapper.selfurnshoopingtrolleyByuserid (userid);
    }

    @Override
    public FurnShoppinTrolley selfurnshoopingtrolleyByshooid(Integer shooid) {
        FurnShoppinTrolley furnShoppinTrolley = furnShoppinTrolleyMapper.selfurnshoopingtrolleyByshooid (shooid);
        return furnShoppinTrolley;
    }

    @Override
    public FurnShoppinTrolley selfurnshoopingtrolleyByshooidbyuid(Integer id, Integer userid, Integer colour) {
        if (id==null||userid==null||colour==null){
            return null;
        }
        FurnShoppinTrolley i = furnShoppinTrolleyMapper.selfurnshoopingtrolleyByshooidbyuid (id, userid, colour);
        return i;
    }

    @Override
    public int furnshoppcount(Integer userid) {
        FurnShoppinTrolleyExample example=new FurnShoppinTrolleyExample ();
        FurnShoppinTrolleyExample.Criteria criteria = example.createCriteria ();
        criteria.andUserIdEqualTo (userid);
        int i = furnShoppinTrolleyMapper.countByExample (example);
        return i;
    }
}